require 'c:/tools/kronos/ruby/line'

class FormalTransition

	attr_accessor :event_name
	attr_accessor :actions
	attr_accessor :destination
	attr_accessor :merge_statement

  def initialize( line )

    @actions     = line.actions
		@merge_statement = Hash.new

		if nil != line.event
			@event_name  = line.event.strip
		end

    if nil != line.end_nameU.index("State")
      @destination = line.end_name.strip
			@merge_statement = nil
    else
			@desination = nil
      @merge_statement = line.merge_actions.clone
    end

  end

end

class FormalStateController

  attr_accessor :states
	attr_accessor :merges

  def initialize( lines )

    @states = Hash.new

		# Fill out state information
    lines.each { |line|

			# Filter out only lines that begin at a state
			if nil != line.start_nameU.index("State")
				if nil == @states[line.start_name.strip]
					# Create array for state commission
					@states[line.start_name.strip] = Array.new
				end
				# Add event, if more than one event exists ERROR
        @states[line.start_name.strip].push FormalTransition.new line
			end

		}

  end

	def printStates

		@states.each { |key, transitions|
			puts key
			transitions.each { |transition|
				puts "\t#{transition.event_name}"
				puts "\t\tactions:"
				puts "\t\t\t#{transition.actions}"
				if nil == transition.destination
					puts "\t\tmerges:"
					puts "\t\t\t#{transition.merge_statement}"
				else
					puts "\t\tdestination:"
					puts "\t\t\t#{transition.destination}"
				end
			}
		}

	end

	def printMerge

		@merges.each { |key, merge|
			puts key
			puts "\t#{merge}"
		}

	end

end
